<template>
  <!--
      	作者：luoyiming
      	时间：2020-06-01
      	描述：福利交易记录
      -->
  <div>

    <div class="common-seach-wrap">
      <el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="手机号">
          <el-input v-model="formInline.phone" placeholder="手机号"></el-input>
        </el-form-item>
        <el-form-item label="车牌号">
          <el-input v-model="formInline.car_number" placeholder="车牌号"></el-input>
        </el-form-item>
        <el-form-item label="类型">
          <el-select v-model="formInline.type_id" placeholder="请选择">
            <el-option label="全部" value="0"></el-option>
            <el-option v-for="(item, index) in gradeList" :key="index" :label="item.welfare_name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="添加时间">
          <div class="block">
            <span class="demonstration"></span>
            <el-date-picker v-model="formInline.reg_date" type="daterange" value-format="yyyy-MM-dd" range-separator="至"
              start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
          </div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="common-seach-wrap">共有:{{totalDataNumber}} 条数据</div>
    <div class="table-wrap">
      <el-table :data="tableData" style="width: 100%" v-loading="loading">
        <el-table-column prop="welfare_id" label="ID" width="60"></el-table-column>
        <el-table-column prop="realname" label="姓名" width="140"></el-table-column>
        <el-table-column prop="phone" label="手机号" width="140"></el-table-column>
        <el-table-column prop="welfares.welfare_name" label="类型" width="140"></el-table-column>
        <el-table-column prop="car_number" label="车牌号" width="140"></el-table-column>
        <el-table-column prop="remark" label="备注"></el-table-column>
        <el-table-column prop="admin_remark" label="后台备注"></el-table-column>
        <el-table-column prop="create_time" label="添加时间" width="140"></el-table-column>
        <el-table-column prop="name" label="操作" width="150">
          <template slot-scope="scope">
            <el-button @click="editWel(scope.row)" type="text" size="small">后台备注</el-button>
            <el-button @click="deleteWel(scope.row)" type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!--分页-->
      <div class="pagination">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background
          :current-page="curPage" :page-size="pageSize" layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  import WelfareApi from '@/api/welfare.js';
  export default {
    components: {},
    data() {
      return {

        /*表单数据*/
        tableData: [],
        /*是否打开添加弹窗*/
        open_add: false,
        /*是否打开编辑弹窗*/
        open_edit: false,
        /*当前编辑的对象*/
        commentData: [],
        loading: true,
        /*一页多少条*/
        pageSize: 15,
        /*一共多少条数据*/
        totalDataNumber: 0,
        /*当前是第几页*/
        curPage: 1,
        gradeList: [],
        formInline: {
          phone: '',
          type_id: '',
          car_number:'',
          reg_date: ''
        },
      };
    },
    created() {
      /*获取文章列表*/
      this.getTableList();
    },
    methods: {

      /*获取文章列表*/
      getTableList() {
        let self = this;
        let Params = self.formInline;
        Params.page = self.curPage;
        WelfareApi.getList(Params, true)
          .then(data => {
            self.loading = false;
            self.tableData = data.data.list.data;
            self.gradeList = data.data.welfare;
            self.totalDataNumber = data.data.list.total;
          })
          .catch(error => {
            self.loading = false;
          });
      },



      /*选择第几页*/
      handleCurrentChange(val) {
        let self = this;
        self.curPage = val;
        self.loading = true;
        self.getTableList();
      },

      /*每页多少条*/
      handleSizeChange(val) {
        this.curPage = 1;
        this.getTableList();
      },
      /*搜索查询*/
      onSubmit() {
        let self = this;
        self.loading = true;
        self.curPage = 1;
        let Params = self.formInline;
        self.getTableList();
      },
      editWel(row) {
        let params = row.welfare_id;
        this.$router.push({
          path: '/welfare/write_off',
          query: {
            id: params
          }
        });
      },
      /*删除文章*/
      deleteWel(row) {
        let self = this;
        self
          .$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
          .then(() => {
            self.loading = true;
            WelfareApi.deleteW({
                  id: row.welfare_id
                },
                true
              )
              .then(data => {
                self.$message({
                  message: data.msg,
                  type: 'success'
                });
                self.loading = false;
                self.getTableList();
              })
              .catch(error => {});
          })
          .catch(() => {});
      },


      handleClick(tab, event) {},

      /*关闭弹窗*/
      closeDialogFunc(e, f) {
        if (f == 'add') {
          this.open_add = e.openDialog;
          if (e.type == 'success') {
            this.getTableList();
          }
        }
        if (f == 'edit') {
          this.open_edit = e.openDialog;
          if (e.type == 'success') {
            this.getTableList();
          }
        }
      }
    }
  };
</script>

<style></style>
